//创建一个大文件.读取出最多的字符
let fs = require("fs");
//判断是否存在文件夹，不存在则创建该文件夹
if (!fs.existsSync("bigdata")) fs.mkdirSync("bigdata");
let str = "qwertyuiopasdfghjklzxcvbnm";
//开始时间
let startAt = new Date().getTime();
//打开文件
let fd = fs.openSync("./bigdata/big.txt", "a");
//写入文件
for (let i = 0; i < 1000000; i++) {
   fs.writeSync(fd, str.slice(Math.floor(Math.random() * (str.length - 1))), str.length - 1);
}
fs.closeSync(fd);
//结束时间
let endAt = new Date().getTime();
console.log(endAt - startAt);
//读取最多的字符
let chatArray = [];
let readStream = fs.createReadStream("./bigdata/big.txt");
readStream.on("data", (chunk) => {
   let str = chunk.toString();
   for (let i = 0; i < str.length; i++) {
      if (chatArray[str[i]] == undefined) {
         chatArray[str[i]] = 1;
      } else {
         chatArray[str[i]] += 1;
      }
   }
});

readStream.on("end", () => {
   console.log(chatArray);
})